package
{
	import flash.display.DisplayObject;
	import flash.display.Shape;
	import flash.display.Sprite;
	import flash.events.Event;
	
	[SWF(width = 500, height = 400, frameRate = 30)]
	public class QueueTest extends Sprite
	{
		private var queue:Queue;
		private var d1:Shape = new Shape();
		private var d2:Shape = new Shape();
		private var d3:Shape = new Shape();
		private var d4:Shape = new Shape();
		private var time:int = 0;
		private var num:int = 0;
		
		public function QueueTest()
		{
			createShape();
			setEvent();
		}
		
		private function createShape():void
		{
			d1.graphics.beginFill(0xff0000);d1.graphics.drawEllipse(0,0,30,30);d1.graphics.endFill();
			d2.graphics.beginFill(0x00ff00);d2.graphics.drawEllipse(60,0,30,30);d2.graphics.endFill();
			d3.graphics.beginFill(0x0000ff);d3.graphics.drawEllipse(30,30,30,30);d3.graphics.endFill();
			d4.graphics.beginFill(0x999999);d4.graphics.drawEllipse(30,72,30,30);d4.graphics.endFill();
			queue = new Queue();
//			var c:DisplayObject;
//			for (var i:int = 1; i < 5; i++)
//			{
//				c = getChildByName("d" + i) as Shape;
//				queue.addItem(c);
//			}
			for (var i:int = 1; i < 5; i++)
			{
				queue.addItem(this["d" + 1]);
			}
//			queue.addItem(d1);
//			queue.addItem(d2);
//			queue.addItem(d3);
//			queue.addItem(d4);
		}
		
		private function setEvent():void
		{
			addEventListener(Event.FRAME_CONSTRUCTED, showQueue);
		}
		
		public function showQueue(e:Event):void
		{
			time++;
			trace(time);
			if (time >= 30)
			{
				time = 0;
				num++;
				switch(num)
				{
					case 1:
						stage.addChild(queue.removeItem(d1));
						break;
					case 2:
						stage.addChild(queue.removeItem(d2));
						break;
					case 3:
						stage.addChild(queue.removeItem(d3));
						break;
					case 4:
						stage.addChild(queue.removeItem(d4));
						removeEventListener(Event.FRAME_CONSTRUCTED, showQueue);
						break;
					default:
						break;
				}
			}
		}
	}
}